package cn.sitedev.lazy;

/**
 * @author qchen
 * @description 双重检测锁式单例
 * 优点: 性能高, 线程安全
 * 缺点: 可读性变差, 不够优雅
 * @date 2020/9/17 1:48
 */
public class Singleton3DoubleCheckLock {
    private static Singleton3DoubleCheckLock instance;

    private Singleton3DoubleCheckLock() {
    }

    public static Singleton3DoubleCheckLock getInstance() {
        // 检查是否要阻塞
        if (instance == null) {
            synchronized (Singleton3DoubleCheckLock.class) {
                // 检查是否要重新创建实例
                if (instance == null) {
                    instance = new Singleton3DoubleCheckLock();
                }
            }
        }
        return instance;
    }
}
